package com.example.drawboard.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;
import com.example.drawboard.R;
import com.example.drawboard.view.CircleImageView;
import com.example.drawboard.view.ColorPicker;


public class LineSelectDialog extends Dialog implements View.OnClickListener {
    private TextView dialog_title,tv_cancel,tv_commit;
    private ImageView gif_image;
    private SeekBar sb_line_weight;
    private int line_weight_value;
    private CircleImageView civ_style;
    private ColorPicker cp_select_color;
    private int color;
    public LineSelectDialog(Context context,int line_weight_value,int color) {
        super(context);
        this.line_weight_value=line_weight_value;
        this.color = color;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setCanceledOnTouchOutside(false);
        Window dialogWindow = getWindow();
        dialogWindow.setGravity(Gravity.CENTER);//设置dialog显示居中
        dialogWindow.setBackgroundDrawableResource(android.R.color.transparent);
        setContentView(R.layout.layout_line_select_dialog);
        findViewById();
        initView();

    }

    private void findViewById(){
        tv_cancel= findViewById(R.id.tv_cancel);
        tv_commit= findViewById(R.id.tv_commit);
        sb_line_weight=findViewById(R.id.sb_line_weight);
        civ_style=findViewById(R.id.civ_style);
        cp_select_color = findViewById(R.id.cp_select_color);
    }

    private void initView(){
        tv_cancel.setOnClickListener(this);
        tv_commit.setOnClickListener(this);
        //cp_select_color.setPaintColor(color);
        sb_line_weight.setProgress(line_weight_value);
        sb_line_weight.setMax(50);
        civ_style.setPaint_width(line_weight_value/2);
        sb_line_weight.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                civ_style.setPaint_width(i/2);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.tv_cancel:

                this.cancel();
                break;
            case R.id.tv_commit:
                int weight = sb_line_weight.getProgress();
                if(callBack!=null){
                    callBack.onCommit(weight);
                }
                this.cancel();
                break;

        }
    }

    private CallBack callBack;

    public void setCallBack(CallBack callBack) {
        this.callBack = callBack;
    }

    public interface CallBack{
        public void onCommit(int process);
    }
}
